﻿using ScFramework.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ScFramework.Core
{
    public class GameMode:IGameMode
    {

        Transform map;
        static IGameMode _instance;
        public static IGameMode Instance
        {
            get
            {
                if(_instance == null)
                {
                    Debug.LogError("GameMode is not set yet");
                }
                return _instance;
            }
        }


        public static void SetGamemode(IGameMode mode,Main m)
        {
            _instance = mode;
            mode.Init(m);
        }


        public Transform GetMapTransform()
        {
            if (map == null) return map = GameObject.Find("Map").transform;
            else return map;

        }

        public bool PosChecker(Vector2 objPos)
        {
            var camePos = cam.CameraPos;
        //    Debug.Log($"camera pos is {camePos}");
            if (Mathf.Abs(objPos.x - camePos.x) > cam.ViewSiz.x) return false;
            if (Mathf.Abs(objPos.y - camePos.y) > cam.ViewSiz.y) return false;
            return true;
        }

        Main _main=null;

        CameraManager cam = null;
        public void Init(Main main)
        {
            _main = main;
            cam = _main.Get<CameraManager>();
        }
    }
}

public interface IGameMode
{

    Transform GetMapTransform();


    void Init(Main main);


    bool PosChecker(Vector2 objPos);

}
